<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { getAdminInfo } from "@/api/admin";

const router = useRouter();
const mobile = ref("");
const password = ref("");

const goLogin = async () => {
  try {
    const res = await getAdminInfo({
      mobile: mobile.value,
      password: password.value,
    });

    console.log("登录返回数据：", res);

    if (res.code === 200) {
      localStorage.setItem("adminInfor", JSON.stringify(res.data));
      router.push("/index");
    }
  } catch (error) {
    console.error("登录失败：", error);
  }
};
</script>
<template>
  <div id="login-view">
    <div class="login-region">
      <div class="login-input login-title">蜂窝煤旅游后台管理系统</div>
      <div class="login-input">
        <el-input placeholder="你的手机号" v-model="mobile" clearable />
      </div>
      <div class="login-input">
        <el-input
          placeholder="你的密码"
          v-model="password"
          clearable
          show-password
        />
      </div>
      <el-button type="success" class="login-input" @click="goLogin"
        >登录</el-button
      >
    </div>
  </div>
</template>
<style scoped lang="scss">
#login-view {
  background-image: url("https://file.moyublog.com/d/file/2023-04-10/2b0e8b76d4fcd03e74dd592bc5a53bde.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  min-height: 100vh;
  .login-region {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    backdrop-filter: blur(5px);
    padding: 30px 100px;
    border-radius: 10px;
    .login-input {
      margin: 20px 0;
      width: 350px;
    }
    .login-title {
      font-size: 30px;
      font-weight: bold;
      text-align: center;
      background-color: inherit !important;
      color: #67c23a;
    }
    div {
      background-color: #f6f7f9;
    }
  }
}
</style>
